import store from "@/store";
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import Home from "../views/Home.vue";

import { message } from "ant-design-vue/es";
const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "Home", 
    component: () => import("../views/acount/Login.vue"),
  },
  {
    path: "/TokenContent",
    name: "TokenContent",
    meta: {
      title: "这就是具体信息拉"
    },
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/TokenContent.vue"),
  },
  {
    path: "/checkUrl",
    name: "checkUrl",
    meta: {
      title: "检测网址"
    },
    component: () =>
      import( "../views/checkUrl.vue"),
  },
  {
    path: "/about", //路径映射路由
    name: "About",
    meta: {
      title: "about",
      // icon
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue"),
  },
  {
    path: "/login", //路径映射路由
    name: "Login",
    meta: {
      title: "登录"
    },
    // component:  Login,s
    component: () => import("../views/acount/Login.vue"),
  },
];
//路由变化

const router = createRouter({
  //有没有也没变化
  history: createWebHashHistory(process.env.BASE_URL),
  routes,
});
router.beforeEach((to, from, next) => {

  document.title = to.meta.title ? to.meta.title as string : "奇怪的系统";

  if (store.state.isLogin || to.fullPath == "/login" || to.fullPath == "/") {

    next();

  } else {
    message.error("必须得先登录", 1);
    next("./login");
  }
});
export default router;
